package com.lixy.demo.highlight_springmvc4.web.ch4_3;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lixy.demo.highlight_springmvc4.domain.DemoObj;

@Controller
@RequestMapping(value="/anno", produces="text/plain;charset=UTF-8")
public class DemoAnnoController {

	@RequestMapping
	public @ResponseBody String index( HttpServletRequest request) {
		return "url: " + request.getRequestURL() + " can be accessed";
	}
	
	@RequestMapping("/pathvar/{str}")
	public @ResponseBody String demoPathVar( @PathVariable String str, HttpServletRequest request ) {
		return "url: " + request.getRequestURL() + " can be accessed, path variable str: " + str;
	}
	
	@RequestMapping("/requestParam")
	public @ResponseBody String passRequestParam( Long id, HttpServletRequest request ) {
		return "url: " + request.getRequestURL() + " can be accessed, id: " + id;
	}
	
	@RequestMapping("/obj")
	@ResponseBody
	public String passObj( DemoObj obj, HttpServletRequest request ) {
		return "url: " + request.getRequestURL() + " can be accessed, obj id: " + 
				obj.getId() + ", obj name: " + obj.getName();
	}
	
	@RequestMapping(value= {"/name1","/name2"})
	public @ResponseBody String remove( HttpServletRequest request ) {
		return "url: " + request.getRequestURL() + " can be accessed";
	}
	
}
